import * as echarts from 'echarts'

/**
 * 基础饼状图
 * @param el
 * @param params
 * @author 赵京涛
 */
export const usePieEchartsHandler = (el, params) => {
  const myChart = echarts.init(el)
  const option = {
    legend: {
      type: 'scroll',
      orient: 'vertical',
      right: 10,
      top: 20,
      bottom: 20,
      textStyle: { //图例文字的样式
        color: '#fff',
      }
    },
    color: params.color,
    tooltip: {
      trigger: 'item',
      className: 'tooltipBox',
      textStyle: {
        color: 'white' // 设置字体颜色为白色  
      }
    },
    grid: {
      top: params.gridTop,
      left: params.gridLeft || '50%',
      right: params.gridRight,
      bottom: params.gridBottom
    },
    toolbox: {
      show: false,
      feature: {
        mark: { show: true },
        dataView: { show: true, readOnly: false },
        restore: { show: true },
        saveAsImage: { show: true }
      }
    },
    series: [
      {
        name: params.name,
        type: 'pie',
        // radius: [50, 250],
        center: ['50%', '50%'],
        avoidLabelOverlap: false,
        labelLine: {
          show: true
        },
        label: {
          show: true,
          position: 'outside',
          color: '#fff',
          formatter: function (params) {
            return params.name + ': ' + params.value;
          }
        },
        data: params.seriesData
      }
    ]
  }
  option && myChart.setOption(option)
}
